﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2006" >
    
    <!-- Control template for the ToggleButton control which is used to expand/collapse the Expander control -->
    <ControlTemplate x:Key="MyToggleButtonControlTemplate" TargetType="{x:Type ToggleButton}">
        <Grid>
            <Rectangle Margin="0,0,0,0" x:Name="Rectangle" Fill="Transparent" Stroke="{DynamicResource DefaultBorder}" StrokeThickness="0"/>
            <Path RenderTransformOrigin="0.331351646560514,0.668211636061805" Fill="{x:Null}" 
                  Stretch="Fill" Stroke="Black" 
                  Width="Auto" Height="Auto" 
                  Data="M4.3499998,4.3690003 L0.49999971,4.3690003 0.53757259,0.50000022 M6.8185094,1.9004906 L2.9685095,1.9004906 3.0060828,-1.9685095" 
                  Margin="11.033,1.358,6.648,4.304" x:Name="path">
                <Path.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="315"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Path.RenderTransform>
            </Path>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true"/>
            <Trigger Property="IsPressed" Value="true"/>
            <Trigger Property="IsChecked" Value="true">
                <Setter Property="RenderTransform" TargetName="path">
                    <Setter.Value>
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                            <SkewTransform AngleX="0" AngleY="0"/>
                            <RotateTransform Angle="135"/>
                            <TranslateTransform X="0" Y="0"/>
                        </TransformGroup>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Fill" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="Rectangle"/>
                <Setter Property="Stroke" Value="{DynamicResource DisabledBorderBrush}" TargetName="Rectangle"/>
                <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- Style for the Expander control -->
    <Style x:Key="ForumExpanderStyle" TargetType="{x:Type Expander}" BasedOn="{x:Null}">
        <Setter Property="Background" Value="{DynamicResource DefaultWindowBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorder}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <Grid Margin="0,0,0,0" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*" x:Name="ContentRow"/>
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0" x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0,0,0,0" Margin="0,0,0,0">
                            <Grid Margin="0,0,0,0" ShowGridLines="false">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="40.455"/>
                                </Grid.ColumnDefinitions>
                                <ToggleButton Template="{DynamicResource MyToggleButtonControlTemplate}" 
                                              Background="{DynamicResource DefaultBrush}" 
                                              IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
                                              OverridesDefaultStyle="True" 
                                              BorderThickness="4,4,4,4" 
                                              Grid.Column="1" Margin="2.955,8.5,12.5,8.5" 
                                              VerticalAlignment="Stretch" 
                                              Width="25" />
                                <ContentPresenter Grid.Column="0" Margin="4,4,0,4" RecognizesAccessKey="True" ContentSource="Header" HorizontalAlignment="Stretch" Width="Auto" Grid.ColumnSpan="1"/>
                            </Grid>
                        </Border>
                        <Border Visibility="Collapsed" Grid.Row="1" x:Name="ExpandSite" Background="{TemplateBinding Background}" BorderBrush="{x:Null}" BorderThickness="0" CornerRadius="0,0,0,0">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Focusable="true"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Setter Property="Visibility" Value="Visible" TargetName="ExpandSite"/>
                            <Setter Property="Background" Value="{DynamicResource OnMouseOverBrush}" TargetName="Border"/>
                            <Setter Property="Background" Value="{DynamicResource TanBrush}" TargetName="ExpandSite" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource DisabledBorderBrush}" TargetName="Border"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource DisabledBorderBrush}" TargetName="Border"/>
                            <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>